import time

import requests
from lxml import etree

# 用户名密码方式
info = 't14409688113668:hyn69tje@j547.kdltps.com:15818'
proxies = {
	"http": f"http://{info}",
	"https": f"http://{info}"
}

res = requests.get("http://httpbin.org/get", proxies=proxies)
print(f"IP: {res.json()['origin']}")


start = 0
headers = {
	"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
}
datas = []

while True:
	print(f"正在爬取第{start}.......")
	res = requests.get(f"https://movie.douban.com/top250?start={start}&filter=", headers=headers)
	tree = etree.HTML(res.text)
	items = tree.xpath('//ol[@class="grid_view"]/li/div[@class="item"]')
	if not items:
		print(f"爬取结束")
		break

	for item in items:
		title = item.xpath('.//div[@class="hd"]//span[@class="title"]/text()')[0]
		datas.append([1 if not datas else datas[-1][0] + 1, title])
	start += 25


print(datas)